//package com.yc.controller;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
//import com.yc.controller.Feign.GoodsControllerFeign;
//import com.yc.controller.Feign.OrderControllerFeign;
//import com.yc.dto.Result;
//import com.yc.entity.Maddress;
//import com.yc.mapper.MaddressMapper;
//import com.yc.util.JwtUtil;
//import io.jsonwebtoken.Claims;
//import org.apache.ibatis.annotations.Param;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.stereotype.Controller;
//
//import javax.servlet.http.Cookie;
//import javax.servlet.http.HttpServletRequest;
//import java.sql.Wrapper;
//import java.util.List;
//
///**
// * <p>
// *  前端控制器
// * </p>
// *
// * @author cxw
// * @since 2025-01-09
// */
//@Controller
//@RequestMapping("//maddress")
//public class MaddressController {
//
//    @Autowired
//    JwtUtil jwtUtil;
//
//    @Autowired
//   GoodsControllerFeign goodsControllerFeign;
//    @Autowired
//    OrderControllerFeign orderControllerFeign;
//@Autowired
//MaddressMapper maddressMapper;
//
//    Integer getUserId(HttpServletRequest request){
//        // 从HTTP请求的Cookie中获取JWT
//        Cookie[] cookies = request.getCookies();
//        String jwt = null;
//        for (Cookie cookie : cookies) {
//            if ("jwt".equals(cookie.getName())) {
//                jwt = cookie.getValue();
//                break;
//            }
//        }
//        // 解析JWT并获取Claims
//        Claims claims = jwtUtil.parseJWT(jwt);
//        // 从Claims中获取用户信息
//        Integer userId = claims.get("userId", Integer.class);
//        return userId;
//    }
//
//    @RequestMapping("saveAddress")
//    Result saveAddress(@RequestBody Maddress maddress, HttpServletRequest request) {
//
//        int uid = this.getUserId(request);
//        LambdaUpdateWrapper<Maddress> luw = new LambdaUpdateWrapper<>();
//        luw.eq(Maddress::getUid, uid); // 确保只更新当前用户的地址
//
//        // 更新地址信息
//        int updatedRows = maddressMapper.update(maddress, luw);
//        if (updatedRows > 0) {
//            // 根据地址ID查询更新后的地址信息
//            Maddress updatedAddress = maddressMapper.selectById(uid);
//            return Result.ok("用户地址修改成功", updatedAddress);
//        } else {
//            // 更新失败
//            return Result.error("用户地址修改失败");
//        }
//    }
//
//}
